# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-astring
_pkgname=astring
pkgver=0.8.5
pkgrel=2
pkgdesc="Alternative String module for OCaml"
url="https://erratique.ch/software/astring"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	ocaml
	ocaml-compiler-libs
	ocaml-findlib
	ocamlbuild
	ocaml-topkg
	cmd:opam-installer
	"
options="!check"  # no tests provided
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://erratique.ch/software/astring/releases/astring-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	ocaml pkg/pkg.ml build
}

package() {
	opam-installer -i \
		--prefix="$pkgdir/usr" \
		--libdir="$pkgdir/$_ocamldir" \
		--docdir="$builddir/.omit" \
		$_pkgname.install
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
b40634cc2053d651bce5c1974996b352ffa48ecac429919113840b2a807efb34387d950f12accb346afd5e40514cb90219d70b00109c30e1450c4e99f65c9856  ocaml-astring-0.8.5.tar.bz2
"
